﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Plugin.RsCms.Models;

namespace Plugin.RsCms.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RsCmsController : ControllerBase
    {
        public RsCmsController()
        {
            
        }
        [HttpGet("")]
        public string GetVersion()
        {
            return "1.0.0";
        }

		[HttpGet("menu/list")]
		public List<RouteMenuItem> GetRouteMenus()
		{
			var items = new List<RouteMenuItem> { };
			if (!User.Identity.IsAuthenticated)
			{
				return items;
			}
			#region 控制中心
			items.Add(new RouteMenuItem
			{
				Name = "dashboard",
				Path = "/dashboard",
				Component = "LAYOUT",
				Redirect = "/dashboard/base",
				Meta = new RouteMenuItemMeta
				{
					Title = "服务中心",
					Icon = "dashboard",
					OrderNo =0
				},
				Children = new RouteMenuItem[]
					{
						new RouteMenuItem
						{
							 Name = "DashboardBase",
							 Path = "base",
							 Component="/dashboard/base/index",
							 Meta=new RouteMenuItemMeta("控制台")
						},
						new RouteMenuItem
						{
							 Name = "ChatBase",
							 Path = "chat",
							 Meta=new RouteMenuItemMeta{ 
							   Title="AI对话", 
								FrameSrc="https://api.coze.cn/open-platform/sdk/chatapp?params=%7B%22chatClientId%22%3A%2296sm2B5TaHw7ax-WaMRbI%22%2C%22chatConfig%22%3A%7B%22bot_id%22%3A%227395755727056338994%22%2C%22user%22%3A%22EVex6MNPHTda3vZzNDBkL%22%2C%22conversation_id%22%3A%221Dy7zvu4cnNs54MOeLnlX%22%7D%2C%22componentProps%22%3A%7B%22layout%22%3A%22pc%22%2C%22lang%22%3A%22zh-CN%22%2C%22uploadable%22%3Atrue%2C%22title%22%3A%2224%E5%B0%8F%E6%97%B6%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%9C%8D%22%2C%22icon%22%3A%22https%3A%2F%2Fpan.rs888.net%2Fassets%2Fimg%2Fkf.png%22%2C%22width%22%3A800%7D%7D",
							 }

						},
						new RouteMenuItem
						{
							 Name = "SitePreview",
							 Path = "preview",
							 Component="/user/share/index",
							 Meta=new RouteMenuItemMeta{
								 Title="分享有赏",
								 Hidden=true
							 }
						}
					}
			});
			#endregion

			#region 档案管理
			//档案管理
			items.Add(new RouteMenuItem
			{
				Name = "archives",
				Path = "/archives",
				Component = "LAYOUT",
				Redirect = "/archives",
				Meta = new RouteMenuItemMeta
				{
					Title = "档案",
					Icon = "edit-2",
					OrderNo = 1,
					Expanded = true
				},
				Children = new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Name = "ArchivesList",
						Path = "index",
						Component="/archives/index",
						Meta=new RouteMenuItemMeta("查询档案")
					},
					new RouteMenuItem
					{
						Name = "archivesEdit",
						Path = "edit",
						Component="/archives/edit",
						Meta=new RouteMenuItemMeta("新建档案")
					},
					new RouteMenuItem
					{
						Name = "bmlist",
						Path = "bmlist",
						Component="/archives/baoming",
						Meta=new RouteMenuItemMeta("报名表")
					}
				}
			});
			#endregion

			#region 用户管理
			items.Add(new RouteMenuItem
			{
				Name = "user",
				Path = "/user",
				Component = "LAYOUT",
				Redirect = "/user/index",
				Meta = new RouteMenuItemMeta
				{
					Title = "用户",
					Icon = "user-circle",
					OrderNo = 1,
					Expanded = true
				},
				Children = new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Name = "UserIndex",
						Path = "index",
						Component="/user/index",
						Meta=new RouteMenuItemMeta{
							Title="会员信息",
							Hidden=true
						}
					},
					new RouteMenuItem
					{
						Name = "UserList",
						Path = "list",
						Component="/user/list",
						Meta=new RouteMenuItemMeta("用户列表")
					},
					new RouteMenuItem
					{
						Name = "UserOpt",
						Path = "opt",
						Component="/user/opt/index",
						Meta=new RouteMenuItemMeta{ 
						 Title="操作记录",
						 Hidden=true
						}
					},
					new RouteMenuItem
					{
						Name = "ShareIndex",
						Path = "share",
						Component="/user/share/index",
						Meta=new RouteMenuItemMeta{
						 Title="分享有赏",
						 Hidden=true
						}
					}
				}
			});
			items.Add(new RouteMenuItem
			{
				Name= "loginRedirect",
				Path= "/loginRedirect",
				Redirect="/login",
				Meta= new RouteMenuItemMeta
				{
					Title="登录页",
					Icon="logout",
					Hidden = true
				},
				Component="/layouts/blank",
				Children=new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Path="index",
						Redirect="/login",
						Component="/layouts/blank",
						Meta=new RouteMenuItemMeta("登录页")
					}
				}
			});
			#endregion

			#region 页面
			items.Add(new RouteMenuItem
			{
				Path="/page",
				Name="pages",
				Component="LAYOUT",
				Redirect="/page/index",
				Meta=new RouteMenuItemMeta
				{
					OrderNo=2,
					Title="页面",
					Icon= "control-platform",
					Expanded=true
				},
				Children=new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Path= "index",
						Name="pageIndex",
						Component="/page/index",
						Meta=new RouteMenuItemMeta
						{
							Title="Page",
							Expanded=true,
							Hidden=true
						}
					},
					new RouteMenuItem
					{
						Path="edit/:id?",
						Name="pagesEdit",
						Component="/page/edit",
						Meta=new RouteMenuItemMeta
						{
							Title="PageEdit",
							Expanded=true,
							Hidden=true
						}
					}
				}
			});
			#endregion

			#region 文章
			items.Add(new RouteMenuItem
			{
				Path="/posts",
				Name="posts",
				Component="LAYOUT",
				Redirect="/posts",
				Meta=new RouteMenuItemMeta
				{
					OrderNo=3,
					Title="文章",
					Icon="edit-2",
					Expanded=false
				},
				Children=new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Path="list",
						Name="postList",
						Component="/posts/list",
						Meta=new RouteMenuItemMeta
						{
							Title="所有文档",
							Hidden=true
						}
					},
					new RouteMenuItem
					{
						Path="drafts",
						Name="postDrafts",
						Component="/posts/drafts",
						Meta=new RouteMenuItemMeta
						{
							Title="草稿",
							Expanded=true
						}
					},
					new RouteMenuItem
					{
						Path="scheduled",
						Name="postScheduled",
						Component="/posts/scheduled",
						Meta=new RouteMenuItemMeta
						{
							Title="计划",
							Expanded=true
						}
					},
					new RouteMenuItem
					{
						Path="published",
						Name="postPublished",
						Component="/posts/published",
						Meta=new RouteMenuItemMeta
						{
							Title="己发布",
							Expanded=true
						}
					},
					new RouteMenuItem
					{
						Path="edit/:id?",
						Name="postsEdit",
						Component="/posts/edit",
						Meta=new RouteMenuItemMeta
						{
							Title="编辑",
							Hidden=true
						}
					}
				}
			});
			#endregion

			#region 标签
			items.Add(new RouteMenuItem
			{
				Path = "/tags",
				Name = "tags",
				Component = "LAYOUT",
				Redirect = "/tags/index",
				Meta = new RouteMenuItemMeta
				{
					OrderNo = 3,
					Title = "标签",
					Icon = "tag",
					Expanded = true,
					Single=true

				},
				Children = new RouteMenuItem[]
				{
					new RouteMenuItem
					{
						Path= "index",
						Name="tagsIndex",
						Component="/tags/index",
						Meta=new RouteMenuItemMeta
						{
							Title="标签",
							Expanded=true,
							Hidden=true
						}
					},
					new RouteMenuItem
					{
						Path="edit/:id?",
						Name="tagsEdit",
						Component="/tags/edit",
						Meta=new RouteMenuItemMeta
						{
							Title="标签",
							Expanded=true,
							Hidden=true
						}
					}
				}
			});
			#endregion

			#region 设置
			if (User.Claims.FirstOrDefault(c => c.Type == "Role").Value == "2")
			{
				items.Add(new RouteMenuItem
				{
					Name = "SysSettings",
					Path = "/settings",
					Redirect = "/settings/base",
					Meta = new RouteMenuItemMeta
					{
						Title = "设置",
						Icon = "setting",
						OrderNo = 10
					},
					Children = new RouteMenuItem[]
					{
						new RouteMenuItem
						{
							Name = "SettingsBase",
							 Path = "base",
							 Component="/settings/base/index",
							 Meta=new RouteMenuItemMeta{
								 Title="设置",
								 Expanded=true,
								 Hidden=true
							 }
						},

						//new RouteMenuItem
						//{
						//	Name = "ApiList",
						//	 Path = "api-list",
						//	 Component="/settings/api/list",
						//	 Meta=new RouteMenuItemMeta("API列表")
						//}
					}
				});
			}
			#endregion

			return items;
		}
	}
}



